import * as request from '../constant/fetch-request'
import HTTP_CODE from '../constant/http-code'
import { message } from 'antd'
import {convertContent} from "../constant/lang-util";

export const addStack = (stack, callback) => {
  return () => {
    (async () => {
      const result = await request.post(`./api/v3/stacks`, stack)
      console.log(result)
      if (result.status === HTTP_CODE.CREATED) {
        message.success(convertContent('添加成功'))
      }
      callback();
    })()
  }
}



export const getAllStacksPage = (page = 1, pageSize = 10) => {
  return dispatch => {
    (async () => {
      const res = await request.get(`./api/v3/stacks/pageable?page=${page}&pageSize=${pageSize}`)

      if (res.status === HTTP_CODE.OK) {
        dispatch({
          type: 'GET_ALL_STACKS_PAGE',
          data: res.body
        })
      }
    })()
  }
}

export const getAllStacks = () => {
  return dispatch => {
    (async () => {
      const res = await request.get(`./api/v3/stacks`)
      if (res.status === HTTP_CODE.OK) {
        dispatch({
          type: 'GET_ALL_STACKS',
          data: res.body
        })
      }
    })()
  }
}
